﻿@model ManufacturerModel

@using Smartstore.Core.Catalog.Brands

@{
    var productManufacturersViewData = new ViewDataDictionary(ViewData);
    productManufacturersViewData["Parent"] = Model;
}

<div asp-validation-summary="All"></div>
<input type="hidden" asp-for="Id" />

<tabstrip id="manufacturer-edit" sm-nav-style="Material" sm-onajaxsuccess="manufacturerEditTab_onAjaxSuccess">
	<tab sm-title="@T("Admin.Common.General")" sm-selected="true">
		<div class="adminContent">
            <div sm-if="Model.Id != 0" class="adminRow">
                <div class="adminTitle">
                    <smart-label asp-for="Id" />
                </div>
                <div class="adminData">
                    <input asp-for="Id" sm-plaintext="true" readonly />
                    <span asp-validation-for="Id"></span>
                </div>
            </div>
            <div class="adminRow">
                <div class="adminTitle">
                    <smart-label asp-for="DisplayOrder" />
                </div>
                <div class="adminData">
                    <editor asp-for="DisplayOrder" />
                    <span asp-validation-for="DisplayOrder"></span>
                </div>
            </div>
            <div class="adminRow">
                <div class="adminTitle">
                    <smart-label asp-for="Published" />
                </div>
                <div class="adminData">
                    <input asp-for="Published" />
                    <span asp-validation-for="Published"></span>
                </div>
            </div>
        </div>

        @(Html.LocalizedEditor<ManufacturerModel, ManufacturerLocalizedModel>("manufacturer-info-localized",
	    @<text>
            <div class="adminContent">
		        <div class="adminRow">
			        <div class="adminTitle">
				        <smart-label asp-for="Locales[item].Name" />
			        </div>
			        <div class="adminData">
				        @*IMPORTANT: Do not delete, this hidden element contains the id to assign localized values to the corresponding language *@
                        <input asp-for="Locales[item].LanguageId" type="hidden" />
                        <input asp-for="Locales[item].Name" />
				        <span asp-validation-for="Locales[item].Name"></span>
			        </div>
		        </div>
		        <div class="adminRow description-container">
			        <div class="adminTitle">
                        <smart-label asp-for="Locales[item].Description" />
			        </div>
                    <div class="adminData wide">
                        <html-editor asp-for="Locales[item].Description" 
                                     save-url="@(Url.PatchLocalizedEntity<Manufacturer>(nameof(Manufacturer.Description), Model.Id, Model.Locales[item].LanguageId))" />
                        <span asp-validation-for="Locales[item].Description"></span>
                    </div>
		        </div>
		        <div class="adminRow description-container d-none">
			        <div class="adminTitle">
                        <smart-label asp-for="Locales[item].BottomDescription" />
			        </div>
                    <div class="adminData wide">
                        <html-editor asp-for="Locales[item].BottomDescription" 
                                     save-url="@(Url.PatchLocalizedEntity<Manufacturer>(nameof(Manufacturer.BottomDescription), Model.Id, Model.Locales[item].LanguageId))" />
                        <span asp-validation-for="Locales[item].BottomDescription"></span>
                    </div>
		        </div>
                <div class="adminRow">
                    <div class="adminTitle">
                        &nbsp;
                    </div>
                    <div class="adminData">
                        <button type="button" class="btn btn-secondary description-toggle-button">
                            <i class="fa fa-right-left"></i>
                            <span>@T("Admin.Catalog.Categories.DescriptionToggle")</span>
                        </button>
                    </div>
                </div>
	        </div>
        </text>
        ,
	    @<text>
            <div class="adminContent">
		        <div class="adminRow">
			        <div class="adminTitle">
				        <smart-label asp-for="Name" />
			        </div>
			        <div class="adminData">
                        <input asp-for="Name" />
				        <span asp-validation-for="Name"></span>
			        </div>
		        </div>
		        <div class="adminRow description-container">
			        <div class="adminTitle">
                        <smart-label asp-for="Description" />
			        </div>
                    <div class="adminData wide">
                        <ai-rich-text asp-for="Description"
                                      entity-name="@Model.Name"
                                      entity-type="Manufacturer"
                                      display-image-options="false"
                                      display-layout-options="false">
                            <html-editor asp-for="Description" save-url="@(Url.PatchEntity<Manufacturer>(nameof(Manufacturer.Description), Model.Id))" />
                        </ai-rich-text>
                        <span asp-validation-for="Description"></span>
                    </div>
		        </div>
		        <div class="adminRow description-container d-none">
			        <div class="adminTitle">
                        <smart-label asp-for="BottomDescription" />
			        </div>
                    <div class="adminData wide">
                        <ai-rich-text asp-for="BottomDescription"
                                      entity-name="@Model.Name"
                                      entity-type="Manufacturer"
                                      entity-id="@Model.Id"
                                      display-layout-options="false"
                                      display-image-options="false">
                            <html-editor asp-for="BottomDescription" save-url="@(Url.PatchEntity<Manufacturer>(nameof(Manufacturer.BottomDescription), Model.Id))" />
                        </ai-rich-text>
                        <span asp-validation-for="BottomDescription"></span>
                    </div>
		        </div>
                <div class="adminRow">
                    <div class="adminTitle">
                        &nbsp;
                    </div>
                    <div class="adminData">
                        <button type="button" class="btn btn-secondary description-toggle-button">
                            <i class="fa fa-right-left"></i>
                            <span>@T("Admin.Catalog.Categories.DescriptionToggle")</span>
                        </button>
                    </div>
                </div>
	        </div>
	    </text>))

        <div class="adminContent">
            <div class="adminRow">
                <div class="adminTitle">
                    <smart-label asp-for="PictureId" />
                </div>
                <div class="adminData">
                    <editor asp-for="PictureId" />
                    <span asp-validation-for="PictureId"></span>
                </div>
            </div>
            <div class="adminRow">
                <div class="adminTitle">
                    <smart-label asp-for="AllowCustomersToSelectPageSize" />
                </div>
                <div class="adminData">
                    <editor asp-for="AllowCustomersToSelectPageSize" />
                    <span asp-validation-for="AllowCustomersToSelectPageSize"></span>
                </div>
            </div>
            <div class="adminRow" id="pnl-pagesize">
                <div class="adminTitle">
                    <smart-label asp-for="PageSize" />
                </div>
                <div class="adminData">
                    <input asp-for="PageSize" />
                    <span asp-validation-for="PageSize"></span>
                </div>
            </div>
            <div class="adminRow" id="pnl-pagesize-options">
                <div class="adminTitle">
                    <smart-label asp-for="PageSizeOptions" />
                </div>
                <div class="adminData">
                    <input asp-for="PageSizeOptions" />
                    <span asp-validation-for="PageSizeOptions"></span>
                </div>
            </div>
            <div class="adminRow">
                <div class="adminTitle">
                    <smart-label asp-for="ManufacturerTemplateId" />
                </div>
                <div class="adminData">
                    <select asp-for="ManufacturerTemplateId" asp-items="ViewBag.ManufacturerTemplates"></select>
                    <span asp-validation-for="ManufacturerTemplateId"></span>
                </div>
            </div>
            <div class="adminRow">
                <div class="adminTitle">
                    <smart-label asp-for="SelectedDiscountIds" />
                </div>
                <div class="adminData">
                    <editor asp-for="SelectedDiscountIds" />
                    <span asp-validation-for="SelectedDiscountIds"></span>
                </div>
            </div>
            <div class="adminRow">
                <div class="adminTitle">
                    <smart-label asp-for="SelectedStoreIds" />
                </div>
                <div class="adminData">
                    <editor asp-for="SelectedStoreIds" />
                    <span asp-validation-for="SelectedStoreIds"></span>
                </div>
            </div>
            <div class="adminRow">
                <div class="adminTitle">
                    <smart-label asp-for="SelectedCustomerRoleIds" />
                </div>
                <div class="adminData">
                    <editor asp-for="SelectedCustomerRoleIds" />
                    <span asp-validation-for="SelectedCustomerRoleIds"></span>
                </div>
            </div>
            <div sm-if="Model.CreatedOn.HasValue" class="adminRow">
                <div class="adminTitle">
                    <smart-label asp-for="CreatedOn" />
                </div>
                <div class="adminData">
                    <div class="form-control-plaintext">
                        @Model.CreatedOn
                    </div>
                </div>
            </div>
            <div sm-if="Model.UpdatedOn.HasValue" class="adminRow">
                <div class="adminTitle">
                    <smart-label asp-for="UpdatedOn" />
                </div>
                <div class="adminData">
                    <div class="form-control-plaintext">
                        @Model.UpdatedOn
                    </div>
                </div>
            </div>
        </div>
	</tab>
	<tab sm-title="@T("Admin.Common.SEO")">
    @(Html.LocalizedEditor<ManufacturerModel, ManufacturerLocalizedModel>("manufacturer-seo-localized",
	    @<text>
            <div class="adminContent">
		        <div class="adminRow">
			        <div class="adminTitle">
				        <smart-label asp-for="Locales[item].MetaTitle" />
			        </div>
			        <div class="adminData">
				        @*IMPORTANT: Do not delete, this hidden element contains the id to assign localized values to the corresponding language *@
                        <input asp-for="Locales[item].LanguageId" type="hidden" />
                        <textarea asp-for="Locales[item].MetaTitle"></textarea>
				        <span asp-validation-for="Locales[item].MetaTitle"></span>
			        </div>
		        </div>
		        <div class="adminRow">
			        <div class="adminTitle">
                        <smart-label asp-for="Locales[item].MetaDescription" />
			        </div>
			        <div class="adminData">
                        <textarea asp-for="Locales[item].MetaDescription"></textarea>
				        <span asp-validation-for="Locales[item].MetaDescription"></span>
			        </div>
		        </div>
		        <div class="adminRow">
			        <div class="adminTitle">
                        <smart-label asp-for="Locales[item].MetaKeywords" />
			        </div>
			        <div class="adminData">
                        <textarea asp-for="Locales[item].MetaKeywords"></textarea>
				        <span asp-validation-for="Locales[item].MetaKeywords"></span>
			        </div>
		        </div>
		        <div class="adminRow">
			        <div class="adminTitle">
                        <smart-label asp-for="Locales[item].SeName" />
			        </div>
			        <div class="adminData">
                        <input asp-for="Locales[item].SeName" />
				        <span asp-validation-for="Locales[item].SeName"></span>
			        </div>
		        </div>
	        </div>
        </text>
        ,
	    @<text>
            <div class="adminContent">
		        <div class="adminRow">
			        <div class="adminTitle">
				        <smart-label asp-for="MetaTitle" />
			        </div>
			        <div class="adminData">
                        <ai-text asp-for="MetaTitle"
                                 entity-name="@Model.Name"
                                 entity-type="Manufacturer"
                                 display-optimization-options="false"
                                 display-word-limit="false"
                                 char-limit="400">
                            <input asp-for="MetaTitle" />
                        </ai-text>
				        <span asp-validation-for="MetaTitle"></span>
			        </div>
		        </div>
		        <div class="adminRow">
			        <div class="adminTitle">
                        <smart-label asp-for="MetaDescription" />
			        </div>
			        <div class="adminData">
                        <ai-text asp-for="MetaDescription"
                                 entity-name="@Model.Name"
                                 entity-type="Manufacturer"
                                 display-optimization-options="false"
                                 display-word-limit="false"
                                 char-limit="4000">
                            <textarea asp-for="MetaDescription"></textarea>
                        </ai-text>
				        <span asp-validation-for="MetaDescription"></span>
			        </div>
		        </div>
		        <div class="adminRow">
			        <div class="adminTitle">
                        <smart-label asp-for="MetaKeywords" />
			        </div>
			        <div class="adminData">
                        <ai-text asp-for="MetaKeywords"
                                 entity-name="@Model.Name"
                                 entity-type="Manufacturer"
                                 display-optimization-options="false"
                                 display-word-limit="false"
                                 char-limit="400">
                            <input asp-for="MetaKeywords" />
                        </ai-text>
				        <span asp-validation-for="MetaKeywords"></span>
			        </div>
		        </div>
		        <div class="adminRow">
			        <div class="adminTitle">
                        <smart-label asp-for="SeName" />
			        </div>
			        <div class="adminData">
                        <input asp-for="SeName" />
                        @if (Model.Id != 0)
                        {
                            @await Component.InvokeAsync("NamesPerEntity", new { entityName = "Manufacturer", entityId = Model.Id })
                        }
				        <span asp-validation-for="SeName"></span>
			        </div>
		        </div>
	        </div>
	    </text>))
	</tab>
	<tab sm-title="@T("Admin.Catalog.Manufacturers.Products")" sm-adaptive-height="true">
        @if (Model.Id > 0)
        {
            <partial name="_Grid.ProductManufacturers" model="null" view-data="productManufacturersViewData" />   
        }
        else
        {
            <div class="alert alert-warning">
                @T("Admin.SaveBeforeEdit")
            </div>
        }
	</tab>
</tabstrip>

<script sm-target-zone="scripts" data-origin="manufacturer-edit">
    function manufacturerEditTab_onAjaxSuccess(tab, pane) {
        applyCommonPlugins(pane);
        reinitFormValidator("#manufacturer-form");
    }

    $(function() {
        // Toggle page size.
        $('#@Html.IdFor(model => model.AllowCustomersToSelectPageSize)').on('change', function() {
            if ($(this).val() != 'false') {
                $('#pnl-pagesize').hide();
                $('#pnl-pagesize-options').show();
            } else {
                $('#pnl-pagesize').show();
                $('#pnl-pagesize-options').hide();
            }
        }).trigger('change');

        // Toggle top\bottom description.
		$('.description-toggle-button').on('click', function() {
			$('.description-container').toggleClass('d-none');
        });
    });
</script>